/*     */ package com.zimbra.cs.index;
/*     */ 
/*     */ import com.google.common.base.Objects;
/*     */ import com.google.common.base.Objects.ToStringHelper;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.LogFactory;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.mailbox.Tag;
/*     */ import com.zimbra.cs.mime.ParsedAddress;
/*     */ import java.text.ParseException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import org.apache.lucene.document.DateTools;
/*     */ import org.apache.lucene.document.Document;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class MessageHit
/*     */   extends ZimbraHit
/*     */ {
/*  49 */   private static final Log LOG = LogFactory.getLog(MessageHit.class);
/*     */   
/*  51 */   private Document document = null;
/*  52 */   private Message message = null;
/*  53 */   private List<MessagePartHit> matchedParts = null;
/*  54 */   private int conversationId = 0;
/*  55 */   private int messageId = 0;
/*  56 */   private ConversationHit conversationHit = null;
/*     */   
/*     */   MessageHit(ZimbraQueryResultsImpl results, Mailbox mbx, int id, Message msg, Document doc, Object sortValue) {
/*  59 */     super(results, mbx, sortValue);
/*  60 */     this.messageId = id;
/*  61 */     this.message = msg;
/*  62 */     this.document = doc;
/*     */   }
/*     */   
/*     */   int getFolderId() throws ServiceException {
/*  66 */     return getMessage().getFolderId();
/*     */   }
/*     */   
/*     */   public int getConversationId() throws ServiceException
/*     */   {
/*  71 */     if (this.conversationId == 0) {
/*  72 */       this.conversationId = getMessage().getConversationId();
/*     */     }
/*  74 */     return this.conversationId;
/*     */   }
/*     */   
/*     */   public void addPart(MessagePartHit part) {
/*  78 */     if (this.matchedParts == null) {
/*  79 */       this.matchedParts = new ArrayList();
/*     */     }
/*  81 */     if (!this.matchedParts.contains(part)) {
/*  82 */       this.matchedParts.add(part);
/*     */     }
/*     */   }
/*     */   
/*     */   public List<MessagePartHit> getMatchedMimePartNames() {
/*  87 */     return this.matchedParts;
/*     */   }
/*     */   
/*     */   public int getItemId()
/*     */   {
/*  92 */     return this.messageId;
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/*     */     try {
/*  98 */       return Objects.toStringHelper(this).add("id", getItemId()).add("conv", getConversationId()).addValue(super.toString()).toString();
/*     */ 
/*     */     }
/*     */     catch (ServiceException e)
/*     */     {
/*     */ 
/* 104 */       return e.toString();
/*     */     }
/*     */   }
/*     */   
/*     */   public boolean isTagged(Tag tag) throws ServiceException {
/* 109 */     return getMessage().isTagged(tag);
/*     */   }
/*     */   
/*     */   void setItem(MailItem item)
/*     */   {
/* 114 */     this.message = ((Message)item);
/*     */   }
/*     */   
/*     */   boolean itemIsLoaded()
/*     */   {
/* 119 */     return this.message != null;
/*     */   }
/*     */   
/*     */   public MailItem getMailItem() throws ServiceException
/*     */   {
/* 124 */     return getMessage();
/*     */   }
/*     */   
/*     */   public Message getMessage() throws ServiceException {
/* 128 */     if (this.message == null) {
/* 129 */       Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailbox().getId());
/*     */       
/* 131 */       int messageId = getItemId();
/*     */       try {
/* 133 */         this.message = mbox.getMessageById(null, messageId);
/*     */       } catch (ServiceException e) {
/* 135 */         LOG.error("Failed to get message mbox=%d,id=%d", Integer.valueOf(mbox.getId()), Integer.valueOf(messageId), e);
/* 136 */         throw e;
/*     */       }
/*     */     }
/* 139 */     return this.message;
/*     */   }
/*     */   
/*     */   public String getName() throws ServiceException
/*     */   {
/* 144 */     if (this.cachedName == null) {
/* 145 */       this.cachedName = getSender();
/*     */     }
/* 147 */     return this.cachedName;
/*     */   }
/*     */   
/*     */   public long getDateHeader() throws ServiceException {
/* 151 */     if ((this.message == null) && (this.document != null)) {
/* 152 */       String dateStr = this.document.get("l.date");
/* 153 */       if (dateStr != null) {
/*     */         try {
/* 155 */           return DateTools.stringToTime(dateStr);
/*     */         } catch (ParseException e) {
/* 157 */           return 0L;
/*     */         }
/*     */       }
/* 160 */       return 0L;
/*     */     }
/*     */     
/* 163 */     return getMessage().getDate();
/*     */   }
/*     */   
/*     */   public String getSender() throws ServiceException {
/* 167 */     return new ParsedAddress(getMessage().getSender()).getSortString();
/*     */   }
/*     */   
/*     */ 
/*     */   public ConversationHit getConversationResult()
/*     */     throws ServiceException
/*     */   {
/* 174 */     if (this.conversationHit == null) {
/* 175 */       Integer cid = Integer.valueOf(getConversationId());
/* 176 */       this.conversationHit = getResults().getConversationHit(getMailbox(), cid.intValue(), this.sortValue);
/* 177 */       this.conversationHit.addMessageHit(this);
/*     */     }
/* 179 */     return this.conversationHit;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/MessageHit.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */